﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.Practices.Unity;

using UnityDemo.Service;

namespace UnityDemo.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ContainerConfig.ContainerConfiguration();
            return View();
        }

        public static void ContainerCode()
        {

            IUnityContainer container = new UnityContainer();
            container.RegisterType<IProductService, MilkService>();
            container.RegisterType<IProductService, SugarService>("_productService");
            IProductService productService = container.Resolve<IProductService>();
            productService.ClassName = productService.GetType().ToString();
            productService.ShowInfo();

            IEnumerable<IProductService> classList = container.ResolveAll<IProductService>();
            foreach (var item in classList)
            {
                item.ClassName = item.GetType().ToString();
                item.ShowInfo();
                ;
            }
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}